<template>
  <div class="">
    <header class="header">
      <div class="title">
        <img src="../../../assets/images/01_11.png" alt="" class="img_zuo" @click="back" />
        <div>隐患整治</div>
      </div>
    </header>
    <div class="main" v-if="data">
      <div class="men-box">
        <div class="list-box">
          <div class="dian">巡查对象-</div>
          <p class="">{{ data.xcdx !== '' ? data.xcdx : '无对象' }}</p>
        </div>
      </div>
      <div class="men-box">
        <div class="list-box">
          <div class="dian">巡查日期-</div>
          <p class="">{{ date }}</p>
        </div>
      </div>
      <div class="men-box">
        <div class="list-box">
          <div class="dian">巡查人-</div>
          <p class="">{{ data.person }}</p>
        </div>
      </div>
      <div v-if="overlay" class="modal-tk"></div>
      <div v-if="overlay" class="modal-main">
        <div class="modal-title">
          <p class="">请选择类别</p>
          <img src="../../../assets/images/tk_x.png" style="width: 18px;height: 18px" @click="jumpClose">
        </div>
        <div class="modal-main-text">
          <div
            class="modal-text"
            :style="yhlbId === it.cxbh ? 'color: #007aff;' : ''"
            v-for="(it, idx) in troubleList"
            :key="idx"
            @click="category(it.cxbh)">{{ it.name }}</div>
        </div>
      </div>
      <div class="" v-for="(item, index) in data.dangerPointVos" :key="index" style="margin-top: 5px;background-color: #fff">
        <div class="main-box">
          <div class="">隐患点</div>
          <p class=""></p>
        </div>
        <div class="main-box">
          <div class="main-text">
            <img src="@/assets/images/logo7.png" alt="" class="imgss">
            <p class="imglist-title" style="margin: 0 15px;">{{ item.name }}</p>
          </div>
          <div class="main-text">
            <p class="">隐患类别</p>
            <div v-if="item.yhlb === ''" class="main-text-xz" @click="jumpOpen(item.noweInfo.patrolTroubleshootInfoId)">
              <p class="">请选择</p>
              <img src="../../../assets/images/appa_r.png" alt="" class="imgss">
            </div>
            <div v-else class="main-text-xz" style="width: 60%">
              <div class="main-btn" @click="jumpOpen(item.noweInfo.patrolTroubleshootInfoId, item.yhlbId)">{{ item.yhlb }}</div>
              <img
                v-if="item.yhlb === '即查即改'"
                src="../../../assets/images/icon-xc-add.png"
                @click="jumpChange(item.id)"
                style="width: 18px">
            </div>
          </div>
        </div>
        <div class="" v-if="item.noweInfo">
          <div class="main-box imglist-title" v-if="item.noweInfo.title !== ''">{{ item.noweInfo.title }}</div>
          <div class="list" v-if="item.noweInfo.contract !== ''">
            <div class="yy" @click="y_play(item.noweInfo.contract, $event)">
              <img src="../../../assets/images/play.png" class="img_yuyin"/>
              <span class="ly_s">{{ item.noweInfo.contractime }}</span>
            </div>
          </div>
          <div class="lists lists1">
            <ul class="lists imgs_ul" v-if="item.noweInfo.imgurl !== ''">
              <li class="img-li" v-for="(items, indexs) in item.noweInfo.imgurl.split(',')" :key="indexs">
                <div class="img-box-main">
                  <div class="img-box">
                    <img :src="showUrl + items" alt="" class="imgs">
                  </div>
                </div>
                <div class="imglist-title">{{ item.noweInfo.imgText.split(',')[indexs] }}</div>
              </li>
            </ul>
            <ul class="video-box" v-if="item.noweInfo.videourl !== ''">
              <li class="video-list" v-for="(obj,i) of item.noweInfo.videourl.split(',')" :key="i">
                <video controls>
                  <source :src="showUrl + obj" type="video/mp4">
                  <source :src="showUrl + obj" type="video/ogg">
                  您的浏览器不支持Video标签。
                </video>
                <div class="del" @click.stop="del(i,'mv')"><img src="../../../assets/images/delete.png" /></div>
              </li>
            </ul>
          </div>
        </div>
        <div class="" v-if="item.rectificaContent">
          <div class="main-box imglist-title" v-if="item.rectificaContent.title !== ''">{{ item.rectificaContent.title }}</div>
          <div class="list" v-if="item.rectificaContent.contract !== ''">
            <div class="yy" @click="y_play(item.rectificaContent.contract, $event)">
              <img src="../../../assets/images/play.png" class="img_yuyin"/>
              <span class="ly_s">{{ item.rectificaContent.contractime }}</span>
            </div>
          </div>
          <div class="lists lists1">
            <ul class="lists imgs_ul" v-if="item.rectificaContent.imgUrl !== ''" >
              <li class="img-li" v-for="(items, indexs) in item.rectificaContent.imgUrl.split(',')" :key="indexs">
                <div class="img-box-main">
                  <div class="img-box">
                    <img :src="showUrl + items" alt="" class="imgs">
                  </div>
                </div>
                <div class="imglist-titles">{{ item.rectificaContent.imgText.split(',')[indexs] }}</div>
              </li>
            </ul>
            <ul class="video-box" v-if="item.rectificaContent.videoUrl !== ''">
              <li class="video-list" v-for="(obj,i) of item.rectificaContent.videoUrl.split(',')" :key="i">
                <video controls>
                  <source :src="showUrl + obj" type="video/mp4">
                  <source :src="showUrl + obj" type="video/ogg">
                  您的浏览器不支持Video标签。
                </video>
                <div class="del" @click.stop="del(i,'mv')"><img src="../../../assets/images/delete.png" /></div>
              </li>
            </ul>
          </div>
        </div>
        <van-popup v-model="shows"  position="bottom">
          <van-datetime-picker
            id="van-datetime-picker"
            v-model="currentDate"
            type="date"
            title="选择年月日"
            :min-date="minDate"
            :max-date="maxDate"
            @cancel="cancel"
            @confirm="confirm(currentDate, item.yhlbId)"
          />
        </van-popup>
        <div
          class="main-box"
          :style="item.time !== '' ? 'justify-content: flex-start' : ''"
          v-if="item.yhlb === '限期整改'">
<!--          <div class="main-texts" v-if="item.time === ''">-->
<!--            <p class="" style="width: 30%">截止日期</p>-->
<!--            <div class="main-text-xz" style="flex: 1;">-->
<!--              <input-->
<!--                style="position: relative;"-->
<!--                type="text"-->
<!--                v-model="item.time"-->
<!--                onfocus="(this.type = 'date')"-->
<!--                class="input-date"-->
<!--                @change="changeDate(item.noweInfo.patrolTroubleshootInfoId, item.time)">-->
<!--              <span v-if="item.time !== ''" class="input-text">{{ item.time }}</span>-->
<!--              <span v-if="item.time === ''" class="input-text">请选择</span>-->
<!--              <img src="../../../assets/images/appa_r.png" alt="" class="imgss">-->
<!--            </div>-->
<!--          </div>-->
<!--          <div class="main-texts" v-else>-->
<!--            <p class="">截止日期-</p>-->
<!--            <div class="main-text-xz">-->
<!--              <input-->
<!--                type="text"-->
<!--                v-model="item.time"-->
<!--                onfocus="(this.type = 'date')"-->
<!--                class="input-date"-->
<!--                @change="changeDate(item.noweInfo.patrolTroubleshootInfoId, item.time, item.yhlbId)">-->
<!--              <span class="input-text">{{ item.time }}</span>-->
<!--            </div>-->
<!--          </div>-->

          <div class="">截止日期</div>
          <div class="main-text-xz" @click="indexss(item.id)">
            <span>{{ item.time !== '' ? `-${item.time}` : '请选择' }}</span>
            <img
              v-if="item.time === ''"
              src="../../../assets/images/appa_r.png"
              class="imgss">
          </div>
        </div>
      </div>
    </div>
    <div style="box-sizing: border-box;padding: 10px;background-color: white">
      <div class="button" :class="btn === 0 ? 'buttons' : ''" id="button" @click="jumpList">完成并签名</div>
    </div>
  </div>
</template>

<script>
import {Toast, Calendar, Popup, DatetimePicker} from "vant";
export default {
  name: "trouble_list",
  data () {
    return {
      overlay: false,
      data: null,
      datas: {},
      patrolId: 0,
      date: '',
      showUrl: '',
      imgList: [],
      number: null,
      troubleList: [],
      troubleId: 0,
      troubleType: 0,
      btn: 0,
      yhlbId: null,
      yhlbIds: null,
      names: '',
      p:null,
      where: '',
      minDate: new Date(2020, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: new Date(),
      shows: false
    };
  },
  components: {
    [Toast.name]: Toast,
    [Calendar.name]: Calendar,
    [Popup.name]: Popup,
    [DatetimePicker.name]: DatetimePicker
  },
  mounted () {
    var _this = this;
    this.where = sessionStorage.getItem("goto");
    this.patrolId = Number(localStorage.getItem('patrolTroubleshootId'));
    this.showUrl = this.$global_msg.Url.hosts;
    this.queryDetails();
    this.query();
    //切换后台
    document.addEventListener("pause", function(){
      _this.stopPlay();
    }, false);
    //物理返回
    // window.addEventListener("popstate", function(){
    //   _this.back();
    // }, false);
  },
  destroyed() {
      setTimeout( () => {
        this.$zoom.showImagesFn.hideContainer();
      })
    },
  methods: {
    cancel () {
      this.shows = false;
    },
    indexss (id) {
      this.shows = true;
      this.yhlbIds = id;
    },
	  stopPlay(){
	    if(this.p){
	      this.p.stop();
	    }
	    this.play_code = 1;
      $('.img_yuyin').attr("src", require('../../../assets/images/play.png'));
      this.$forceUpdate();
	  },
	  back(){
	    this.stopPlay();
      this.$router.back();
	  },
    //  查询隐患类别
    query () {
      this.axios.get(`${this.$global_msg.Url.host}/partroInspection/selectDangerType`)
        .then(res => {
          console.log(res)
          let a = res.data.rows;
          let b = res.data.rows[1];
          a.map((res, index) => {
            if (res.cxbh === 101) {
              a.splice(index, 1)
            }
          })
          a.unshift(b)
          this.troubleList = a;
      })
    },
    //  查询详情
    queryDetails () {
      const that = this;
      const params = {
        patrolTroubleshoot: this.patrolId
      };
      that.axios.get(`${that.$global_msg.Url.host}/partroInspection/dangerList`,
        { params }).then(res => {
          console.log(res)
        if (res.data.code === 200) {
          that.data = res.data.rows;
          let date = new Date(this.data.xctime);
          that.date = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
          that.queryBtn();
        } else {
          console.log('获取数据失败！');
        }
      })
    },
    //  是否可以确定跳转
    queryBtn () {
      let a = [];
      let b = [];
      let c = [];
      this.data.dangerPointVos.map((res) => {
        a.push(res.yhlbId);
        if (res.yhlbId === 101) {
          b.push(res.rectificaContent);
        }
        if (res.yhlbId === 100) {
          c.push(res.time);
        }
      })
      if (a.indexOf(null) === -1) {
        if (a.indexOf(101) !== -1) {
          if (b.indexOf(null) === -1) {
            if (c.indexOf('') === -1) {
              this.btn = 1;
            } else {
              this.btn = 0;
            }
          } else {
            this.btn = 0;
          }
        } else if (a.indexOf(100) !== -1){
          if (c.indexOf('') === -1) {
            this.btn = 1;
          } else {
            this.btn = 0;
          }
        } else {
          this.btn = 1;
        }
      }
    },
    //  跳转签名页
    jumpList () {
      const that = this;
      const params = {
        patrolTroubleshoot: that.patrolId
      };
      var xcpc_da_obj = localStorage.getItem("xcpc_da_obj")?JSON.parse(localStorage.getItem("xcpc_da_obj")):{};
      if(xcpc_da_obj.id||xcpc_da_obj.id===0){
        params.daId = xcpc_da_obj.id;
        var _type = null;
        if(xcpc_da_obj.type === 'zgf'){
          _type = 1;
        }else if(xcpc_da_obj.type === 'jxmd'){
          _type = 2;
        }else if(xcpc_da_obj.type === 'jzw'){
          _type = 3;
        } else if(xcpc_da_obj.type === 'zdqy') {
          _type = 4;
        } else if(xcpc_da_obj.type === 'zjgd') {
          _type = 5;
        } else if (xcpc_da_obj.type === 'qt') {
          _type = 6;
        }
        params.type = _type;
        if(!xcpc_da_obj.oldjwd){
          params.jwd = xcpc_da_obj.jwd;
        }
      }
      that.axios.get(`${that.$global_msg.Url.host}/partroInspection/dangerListConfirm`,
        { params }).then(res => {
        console.log(res)
        if (res.data.code === 200) {
          that.stopPlay();
          sessionStorage.setItem('signature_router', '/trouble_list')
          this.$router.push({
            // path: '/community_list',
            path: '/signature_be_list',
          })
        }
      })
    },
    //  打开弹框
    jumpOpen (id, ids) {
      this.overlay = true;
      document.body.style.overflow = 'hidden';
      this.troubleId = id;
      this.yhlbId = ids;
      console.log(id, ids)
    },
    //  关闭弹框
    jumpClose () {
      this.overlay = false;
      document.body.style.overflow = ''
    },
    //  点击类别
    category (key) {
      this.troubleType = key;
      this.trouble(this.troubleId, key);
    },
    //  日期
    confirm (time, keys) {
      this.shows = false;
      let times = time.getFullYear() + '-' +
        ((time.getMonth() + 1) < 10 ? `0${(time.getMonth() + 1)}` : time.getMonth() + 1) + '-' +
        (time.getDate() < 10 ? `0${time.getDate()}` : time.getDate())
      let a;
      if (this.troubleType !== 0) {
        a = this.troubleType;
      } else {
        a = keys;
      }
      this.trouble(this.yhlbIds, a, times);
    },
    //  保存隐患类别
    trouble (id, key, time) {
      console.log(id)
      const that = this;
      const params = {
        patrolTroubleshoot: that.patrolId,
        patrolTroubleshootInfoId: id,
        type: key,
        time: time
      };
      that.axios.get(`${that.$global_msg.Url.host}/partroInspection/saveDangerType`,
        { params }).then(res => {
        console.log(res)
        if (res.data.code === 200) {
          that.overlay = false;
          document.body.style.overflow = '';
          this.queryDetails();
        } else {
          this.queryDetails();
          Toast('修改失败！');
        }
      })
    },
    //  跳转
    jumpChange (id) {
      this.stopPlay();
      this.$router.push({
        path: '/trouble_list_change',
        query: { id }
      })
    },
    //  播放语音
    y_play(yy_path, e) {
      var dom = $(e.currentTarget).find(".img_yuyin")
      console.log(dom)
      // $(dom).attr("src", require('../../assets/images/play_dt.gif'))
      console.log(yy_path);
      var _this = this;
      _this.p = null;
      console.log(_this.$global_msg.Url.host + yy_path);
      _this.p = plus.audio.createPlayer(_this.$global_msg.Url.hosts+"" + yy_path);
      if (_this.play_code == 1) {
        $(dom).attr("src", require('../../../assets/images/play_dt.gif'))

        console.log("进入播放");
        _this.play_code = 2;
        _this.p.play(
          () => {
            //播放完毕
            _this.play_code = 1;
            $(dom).attr("src", require('../../../assets/images/play.png'));
            _this.p.close();
          },
          function (e) {
			_this.play_code = 1;
			$(dom).attr("src", require('../../../assets/images/play.png'));
			_this.p.close();
            alert("Audio play error: " + e.message);
          }
        );
      } else {
        _this.play_code = 1;
        $(dom).attr("src", require('../../../assets/images/play.png'));
        _this.p.close();
      }
    },
  }
}
</script>

<style scoped>
  * {
    box-sizing: border-box;
  }
  .men-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 50px 40px;
    border-bottom: 1Px solid #f2f2f2;
    background-color: #ffffff;
  }
  ::-webkit-calendar-picker-indicator {
    border: none;
    border-radius: 2px;
    box-shadow: inset 0 1px #fff, 0 1px #eee;
    background-color: transparent;
    background-image: -webkit-linear-gradient(top, transparent, transparent);
    color: #666;
  }
  input[type="date"]{ -webkit-appearance: none;}
  .input-date {
    z-index: 99;
    display: flex;
    justify-content: flex-end;
    width: 0.75rem;
    margin-left: 0.4rem;
  }
  .input-text {
    /*position: absolute;*/
    /*right: 100px;*/
    margin-left: -1.1rem;
    z-index: 98;
  }
  .video-box {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 100%
  }
  /* 视频列表 */
  .video-list{
    padding-top: 0.259259rem;
    margin-bottom:0.37037rem;
    width: 100%;
    height: auto;
    display: flex;
    position: relative;
    flex-direction: column;
    border-top: 1px #f2f2f2 solid;
  }
  .video-list video{
    margin-left: 0.37037rem;
    margin-right: 0.37037rem;
    width: auto;
    height: 4.87037rem !important;
    margin-top: 0.259259rem;
  }
  .video-list video:first-child{
    margin-top: 0;
  }
  .video-list .del{
    width: 1rem;
    height: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    right: 0;
    border-radius: 0.925925rem;
    overflow: hidden;
  }
  .video-list .del img{
    width: 100%;
    height: 100%;
  }
  .video-list .del img{
    width: 100%;
    height: 100%;
  }
  .img-group {
    width: 1.388888rem;
    height: 100%;
    position: absolute;
    top: 0;
    right: 0;
    z-index: 12;
    border-left: 1px #FFFFFF solid;
    display: flex;
    flex-direction: column;
  }
  .img-btn {
    height: 100%;
  }
  .del-btn {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    font-size: 78px;
  }
  .header {
    height: 1.8519rem;
    background: #007aff;
    padding-top: 0.8333rem;
    box-sizing: border-box;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 20;
    font-size: 0.388888rem;
  }
  .title {
    padding: 0 0.3704rem;
    display: flex;
    align-items: center;
    color: #fff;
  }
  .title>div {
    width: 100%;
    font-size: 0.4444rem;
    text-align: center;
  }
  .img_zuo {
    width: 0.2593rem;
    height: 0.463rem;
  }
  .main {
    padding-top: 1.8519rem;
    background-color: #f2f2f2;
  }
  .main-box {
    display: flex;
    justify-content: space-between;
    padding: 50px 0.3rem;
    border-bottom: 1px solid #f2f2f2;
    width: 100%;
    background-color: #fff;
  }
  .text-rgt {
    color: #999;
  }
  .main-text {
    width: 50%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .main-texts {
    width: 100%;
    display: flex;
    align-items: center;
  }
  .main-text:first-child {
    justify-content: left;
  }
  .main-text-xz {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    color: #999;
  }
  .input-name {
    right: 1.6344rem;
  }
  .imgss {
    width: 62px;
  }
  .main-box textarea {
    width: 100%;
    /*padding-top: 0.3704rem;*/
    overflow: hidden;
    pointer-events: none;
  }
  .main-btn {
    background-color: #007aff;
    color: #fff;
    width: 100%;
    padding: 10px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 25px;
    margin-right: 10px;
  }
  .imgs_ul {
    padding: 0.3rem 0.4rem;
    width: 100%;
  }
  .lists {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    border-bottom: 1Px solid #f2f2f2;
  }
  .lists1 {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .img-li {
    width: 50%;
    padding: 10px;
  }
  .img-box-main {
    border: 1px #CCCCCC solid;
    border-radius: 30px;
    overflow: hidden;
  }
  .img-box {
    height: 2.814814rem;
    background-size: 100% 100%;
    position: relative;
    overflow: hidden;
    display: flex;
  }
  .imglist-title {
    display: flex;
    text-align: justify;
    text-justify: newspaper;
    word-break: break-all;
    justify-content: flex-start;
  }
  .imglist-titles {
    display: flex;
    text-align: justify;
    text-justify: newspaper;
    word-break: break-all;
    justify-content: flex-start;
  }
  .imgs {
    width: 100%;
    height: 100%;
    z-index: 11;
    object-fit: cover;
  }
  .yy img {
    margin: 0 0.2rem;
    width: 0.4rem;
  }
  .yy {
    width: 2.3rem;
    height: 0.8rem;
    border: 1Px solid #f2f2f2;
    display: flex;
    border-radius: 0.2rem;
    align-items: center;
  }
  .list {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1Px solid #f2f2f2;
    height: 1.3rem;
    padding: 0 0.4rem;
  }
  .modal-tk {
    z-index: 1111;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, .7);
  }
  .modal-main {
    z-index: 1112;
    position: fixed;
    max-height: 100%;
    padding: 0 50px;
    width: 80%;
    top: 50%;
    left: 50%;
    background-color: #fff;
    transform: translate3d(-50%, -50%, 0);
    transition: transform 0.3s;
    border-radius: 25px;
  }
  .modal-title {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #f2f2f2;
    padding: 30px 0;
  }
  .modal-text {
    padding: 50px 0;
    border-bottom: 1px solid #f2f2f2;
  }
  .button {
    width: 100%;
    height: 1rem;
    color: white;
    text-align: center;
    line-height: 1rem;
    /*background-color: #8f8f94;*/
    background-color: #2B6CFE;
    border-radius: 0.105185rem;
  }
  .list-box {
    display: flex;
    align-items: center;
    white-space: normal;
  }
  .dian {
    word-break: keep-all;
  }
  .buttons {
    pointer-events: none;
    background-color: #8f8f94;
  }
</style>
<style>
  #van-datetime-picker>div {
    height: 1.25rem;
    line-height: 1.25rem;
  }
  #van-datetime-picker>div>div {
    font-size: 0.3888888888888889rem;
  }
  #van-datetime-picker>div>button {
    padding: 0 50px;
    font-size: 0.3888888888888889rem;
  }
</style>
